using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Resources;
using System.Reflection;
using System.Threading;
using System.Globalization;

using SypConst.Garbage;

namespace SypGui.CreateForms
{
    public class SypUserControl : UserControl
    {
        public SetText OutputMethod = null;
        private int siteId = -1;

        public int SiteId
        {
            set
            {
                lock (this)
                {
                    siteId = value;
                }
            }
            get
            {
                lock (this)
                {
                    return siteId;
                }
            }

        }

        protected virtual void InitializeRessources() { }

        protected virtual void InitializeComponent() { }

        protected virtual void InitializeUC() 
        {
            this.Location = new System.Drawing.Point(-4, 0);
            this.Size = new System.Drawing.Size(399, 222);
            this.TabIndex = 0;
        }

        public virtual void ProcessConfig()
        {
        }

        protected string GetRessources(string key)
        {
            ResourceManager resourceManager = new ResourceManager("Syp.Resources", GetType().Assembly);
            
            ResourceSet CurrentResource = resourceManager.GetResourceSet(new CultureInfo(SypGarbageConf.Instance().Language), true, false);
            if (CurrentResource != null)
            {
                string val = CurrentResource.GetString(key);
                SypGarbage.free(CurrentResource);
                SypGarbage.free(resourceManager);
                return val;
            }
            SypGarbage.free(CurrentResource);
            SypGarbage.free(resourceManager);
            return null;
        }

        public virtual void Reset() { }

        public SypUserControl()
        {
            InitializeComponent();
        }

        public SypUserControl(SetText OutputMethod)
        {
            InitializeComponent();
            this.OutputMethod = OutputMethod;
            this.siteId = SypGarbageConf.Instance().GetCurrentId();
            InitializeUC();
            InitializeRessources();
        }

    }
}
